package com.yanghx.springtxjta.web;

import com.yanghx.springtxjta.dao.CustomerRepository;
import com.yanghx.springtxjta.domain.Customer;
import com.yanghx.springtxjta.service.CustomerServiceTxInAnnotation;
import com.yanghx.springtxjta.service.CustomerServiceTxInCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * TODO 好像实现方式不对
 * @author yangHX
 * createTime  2019/8/7 22:23
 */
@RestController
@RequestMapping(value = "/api/customer")
@Slf4j
public class CustomerResource {


    @Resource
    private CustomerServiceTxInAnnotation customerServiceTxInAnnotation;
    @Resource
    private CustomerServiceTxInCode customerServiceTxInCode;
    @Resource
    private CustomerRepository customerRepository;

    @PostMapping(value = "/annotation")
    public Customer createInAnnotation(@RequestBody Customer customer) {
        log.info("CustomerResource crate in annotation create customer : {}", customer);
        return customerServiceTxInAnnotation.create(customer);

    }


    @PostMapping(value = "/code")
    public Customer createInCode(@RequestBody Customer customer) {
        log.info("CustomerResource crate in code create customer : {}", customer);
        return customerServiceTxInCode.create(customer);
    }

    @GetMapping
    public List<Customer> getAll() {
        return customerRepository.findAll();

    }

}
